<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/31
 * Time: 18:21
 */
namespace App\Ordersys\Controllers\Admin;
use App\Base\Controllers\Controller;
use App\Ordersys\Models\LuckDrawAwaerModel;
use Illuminate\Http\Request;


class DrawawaerController  extends Controller
{

    /**
     * @return LuckDrawAwaerModel
     */
    public function getLuckDrawAwaerModel(){
        return app()->make(LuckDrawAwaerModel::class);
    }
    public function index(Request $request){

        $rmsg=$this->return_arr();
        if ($request->getMethod() == 'POST') {
            $where=function($query) use ($request){
                $truename=$request->input("truename");
                if(!empty($truename)){
                    $query->where("truename","like", '%' . $truename. '%');
                }
                $status=$request->input("status","");
                if($status!=""){
                   $query->where("status",$status);
                }
            };
            $pagelist=$this->getLuckDrawAwaerModel()->newQuery()->where($where)->orderBy("create_time","desc")->paginate(10);
            if(!empty($pagelist -> items())){
                foreach($pagelist -> items()  as $k => $v){
                    $v["award_name"] = $rmsg[$v->awaer];
                    $data[] = $v;
                    $custom = collect(['data' => $data]) ;
                }
                $custom->merge($pagelist);
            }
            return $pagelist;
        }
      return view("ordersys.drawawaer.index");
    }

    public function changeStatus(Request $request){
       $data=$request->all();
        if(empty($data['status'])){
            $data['status']=0;
        }
        $data["apply_uid"]=UID;
        return $this->getLuckDrawAwaerModel()->newQuery()->updateOrCreate(["id"=>$data['id']],$data);
    }

    public function return_arr(){
        return [
            "很遗憾您未中奖，再接再厉",
            "恭喜您减免36000元",
            "恭喜您获得减免24000元",
            "恭喜您获得减免12000元",
            "恭喜您获得减免6000元",
            "恭喜您获得免费体验券",
            "恭喜您获得免费体验券",
        ];
    }

}